#!/usr/local/python27
# coding=utf8

from mock_proxy_plugin.proxy import ProxyHandler

KEY_URL = 'url'
BEFORE_TIME="before_sleep"
AFTER_TIME="after_sleep"
HTTPCODE="httpcode"

ROUTER_PATH = "path"
ROUTER_PROXY_URL = "proxy_url"


class MockProxyPlugin(object):
    def get_handler(self, options, **kwargs):

        url_path = kwargs.get(ROUTER_PATH)

        url = options[KEY_URL] if KEY_URL in options else ""
        before_sleep = options[BEFORE_TIME] if BEFORE_TIME in options else ""
        after_sleep = options[AFTER_TIME] if AFTER_TIME in options else ""
        httpcode = options[HTTPCODE] if HTTPCODE in options else ""
        if url and url_path:
            
            kargs={
                ROUTER_PROXY_URL: url,
                BEFORE_TIME: before_sleep,
                AFTER_TIME: after_sleep,
                HTTPCODE: httpcode
                   }
            
            handler = (url_path, ProxyHandler, kargs)
            return handler
        return None

